Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daemon: FakeCommand usage requires reaper.Start() #247

Merged
merged 1 commit into from
Aug 1, 2023

Conversation

flotter
Copy link
Contributor

@flotter flotter commented Jun 26, 2023

The usage of testutil.FakeCommand requires the test environment to start and stop the reaper in the case where the reaper option is enabled.

For example, in internals/daemon/daemon_test.go:

:
cmd := testutil.FakeCommand(c, "shutdown", "", true) :

However, in daemon_test.go, the code is currently relying on the service manager, provided by the overlord, to start the reaper. This is not a safe solution as not all test implementations may actually run the real overlord code, and even if they do, we have a potential race condition.

daemon.Init() -> overlord.New() -> servstate.NewManager() -> reaper.Start()

The following changes are introduced:

  • Add reaper.Start() and reaper.Stop() to the daemon test setup and teardown.

  • Add a reaper based test for testutil.FakeCommand().

Copy link
Contributor

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me, thanks

@flotter flotter removed the request for review from atesburak June 28, 2023 12:39
@flotter flotter added the High Priority Look at me first label Jun 28, 2023
@flotter
Copy link
Contributor Author

flotter commented Jun 28, 2023

This PR is mostly theoretical, but aligns with the work done here #249

Copy link
Member

@jnsgruk jnsgruk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for the analysis on this Fred. Going ahead with merge as this is just an improvement to the test suite.

The usage of testutil.FakeCommand requires the test environment to start
and stop the reaper in the case where the reaper option is enabled.

For example, in internals/daemon/daemon_test.go:

:
cmd := testutil.FakeCommand(c, "shutdown", "", true)
:

However, in daemon_test.go, the code is currently relying on the service
manager, provided by the overlord, to start the reaper. This is not a
safe solution as not all test implementations may actually run the real
overlord code, and even if they do, we have a potential race condition.

daemon.Init() -> overlord.New() -> servstate.NewManager() -> reaper.Start()

The following changes are introduced:

- Add reaper.Start() and reaper.Stop() to the daemon test setup and teardown.

- Add a reaper based test for testutil.FakeCommand().
@jnsgruk jnsgruk merged commit 7862f99 into canonical:master Aug 1, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
High Priority Look at me first
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants